package com.lizardmind.haofudoctor.ui.studio

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.linxiao.framework.adapter.BaseAdapter
import com.linxiao.framework.adapter.DividerGridItemDecoration
import com.linxiao.framework.fragment.BaseFragment
import com.linxiao.framework.util.color
import com.linxiao.framework.util.getDataBinding
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.databinding.FragmentStudioBinding
import com.lizardmind.haofudoctor.databinding.ItemStudioBinding
import com.lizardmind.haofudoctor.other.StudioBean
import com.lizardmind.haofudoctor.ui.diagnosis.visit.DiyVisitTimeActivity
import com.lizardmind.haofudoctor.ui.main.MainActivity
import com.lizardmind.haofudoctor.ui.other.PatientsEduWebActivity
import com.lizardmind.haofudoctor.ui.studio.sickEducation.SickEducationActivity
import com.lizardmind.haofudoctor.ui.studio.allPatients.PatientsActivity
import com.lizardmind.haofudoctor.ui.studio.diagnose.DiagnoseStudioActivity
import com.lizardmind.haofudoctor.ui.studio.gongGao.GongGaoAndSetActivity
import com.lizardmind.haofudoctor.ui.studio.gongGao.MenZhenDataSetActivity
import com.lizardmind.haofudoctor.ui.studio.serviceSetting.ServiceSettingActivity
import com.lizardmind.haofudoctor.ui.studio.signFamily.SignFamilyActivity
import com.lizardmind.haofudoctor.ui.studio.visit.VisitStudioActivity
import kotlinx.android.synthetic.main.fragment_studio.*
import kotlinx.android.synthetic.main.include_title_text.view.*
import kotlinx.android.synthetic.main.layout_workspace_bottomview.view.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.support.v4.act
import org.jetbrains.anko.support.v4.toast

/**
 * 工作室
 * Created by Extends on 2017/10/13 13:10
 */

class StudioFragment : BaseFragment() {

    private val listBean= arrayListOf<StudioBean>(
            StudioBean("签约家庭",R.mipmap.sign_family, SignFamilyActivity::class.java),
            StudioBean("全部患者",R.mipmap.all_patient, PatientsActivity::class.java),
            StudioBean("服务设置",R.mipmap.service_set, ServiceSettingActivity::class.java),
            StudioBean("门诊信息",R.mipmap.hospital_message, MenZhenDataSetActivity::class.java),
            StudioBean("公告管理",R.mipmap.public_notice_manage, GongGaoAndSetActivity::class.java),
//            StudioBean("公告管理",R.mipmap.public_notice_manage, BianZhengKaiFangActivity::class.java),
            StudioBean("问诊单管理",R.mipmap.wen_zhen_dan, DiagnoseStudioActivity::class.java),
            StudioBean("开方购药",R.mipmap.buy_medicine, KaiFangGouYaoActivity::class.java),
            StudioBean("随访复诊",R.mipmap.sui_fang, VisitStudioActivity::class.java),
            StudioBean("健康教育",R.mipmap.health_teach, SickEducationActivity::class.java),
            StudioBean("收入管理",R.mipmap.income_manage, IncomeManageActivity::class.java),
            StudioBean("推荐同行",R.mipmap.recommend_doctor, RecommendPeerActivity::class.java)
    )

    private val mAdapter by lazy{ BaseAdapter<StudioBean,ItemStudioBinding>(R.layout.item_studio,listBean) }
    private val bottomView: View by lazy{ LayoutInflater.from(context).inflate(R.layout.layout_workspace_bottomview,con,false)}

    private lateinit var con :ViewGroup
    val binding by lazy { getDataBinding<FragmentStudioBinding>(R.layout.fragment_studio) }
    override fun onCreatRootView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        con = container!!
        return binding.root
    }

    override fun onInitView(savedInstanceState: Bundle?) {
        //初始化title
        workSpace_title.apply {
            imgRight.setImageResource(R.mipmap.search)
            imgRight.onClick { toast("不知道搜索什么") }
            titleText.text="工作室"
        }

        bottomView.tvName.text="大家助理"
        bottomView.tvContent.text="老师，你好。为了保证良好的使用体验以......"
        bottomView.imgIcon.setImageResource(R.mipmap.people_management)

        //初始化recyclerView
        recyclerView_workSpace.apply {
            layoutManager=GridLayoutManager(context,3)
            adapter=mAdapter
            addItemDecoration(DividerGridItemDecoration(context,2f,context.color(R.color.windowBackground)))
        }

        mAdapter.footerView = bottomView
        mAdapter.onBind { itemBingding, position, data ->
            itemBingding.root.onClick {
                if(data.c!=MainActivity::class.java){
                    startActivity(Intent(act,data.c))
                }
            }
        }
    }
}